home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / General / GCC 1.37.1r15 / Sources / varasm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  66.4 KB  |  2,519 lines  |  [TEXT/MPS ]

  1. /* Output variables, constants and external declarations, for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This file handles generation of all the assembler code
  23.    *except* the instructions of a function.
  24.    This includes declarations of variables and their initial values.
  25.  
  26.    We also output the assembler code for constants stored in memory
  27.    and are responsible for combining constants with the same value.  */
  28.  
  29. #include <stdio.h>
  30. #include <setjmp.h>
  31. /* #include <stab.h> */
  32. #include "config.h"
  33. #include "rtl.h"
  34. #include "tree.h"
  35. #include "flags.h"
  36. #include "expr.h"
  37. #include "hard-reg-set.h"
  38.  
  39. #include "obstack.h"
  40.  
  41. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  42.  
  43. /* File in which assembler code is being written.  */
  44.  
  45. extern FILE *asm_out_file;
  46.  
  47. extern struct obstack *current_obstack;
  48. extern struct obstack *saveable_obstack;
  49. extern struct obstack permanent_obstack;
  50. #define obstack_chunk_alloc xmalloc
  51. extern int xmalloc ();
  52.  
  53. /* Number for making the label on the next
  54.    constant that is stored in memory.  */
  55.  
  56. int const_labelno;
  57.  
  58. /* Number for making the label on the next
  59.    static variable internal to a function.  */
  60.  
  61. int var_labelno;
  62.  
  63. /* Nonzero if at least one function definition has been seen.  */
  64. static int function_defined;
  65.  
  66. extern FILE *asm_out_file;
  67.  
  68. #ifdef APPLE_C
  69. /* Magic function for building direct definitions. */
  70. char *build_direct_defn ();
  71. #endif /* APPLE_C */
  72. static char *compare_constant_1 ();
  73. static void record_constant_1 ();
  74. void assemble_name ();
  75. void output_addressed_constants ();
  76. void output_constant ();
  77. void output_constructor ();
  78.  
  79. #ifdef EXTRA_SECTIONS
  80. static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
  81.   = no_section;
  82. #else
  83. static enum in_section {no_section, in_text, in_data} in_section
  84.   = no_section;
  85. #endif
  86.  
  87. /* Define functions like text_section for any extra sections.  */
  88. #ifdef EXTRA_SECTION_FUNCTIONS
  89. EXTRA_SECTION_FUNCTIONS
  90. #endif
  91.  
  92. /* Tell assembler to switch to text section.  */
  93.  
  94. void
  95. text_section ()
  96. {
  97.   if (in_section != in_text)
  98.     {
  99.       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
  100.       in_section = in_text;
  101.     }
  102. }
  103.  
  104. /* Tell assembler to switch to data section.  */
  105.  
  106. void
  107. data_section ()
  108. {
  109.   if (in_section != in_data)
  110.     {
  111.       if (flag_shared_data)
  112.     {
  113. #ifdef SHARED_SECTION_ASM_OP
  114.       fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
  115. #else
  116.       fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  117. #endif
  118.     }
  119.       else
  120.     fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  121.  
  122.       in_section = in_data;
  123.     }
  124. }
  125.  
  126. /* Determine if we're in the text section. */
  127.  
  128. int
  129. in_text_section ()
  130. {
  131.   return in_section == in_text;
  132. }
  133.  
  134. /* Create the rtl to represent a function, for a function definition.
  135.    DECL is a FUNCTION_DECL node which describes which function.
  136.    The rtl is stored into DECL.  */
  137.  
  138. void
  139. make_function_rtl (decl)
  140.      tree decl;
  141. {
  142. #ifdef APPLE_C
  143.   /* Pascal functions must be mapped into all-upper-case.  Don't worry
  144.      about whether there are function names differing only in case, MPW
  145.      doesn't either... */
  146.   if (TREE_PASCAL (decl))
  147.     string_upcase(DECL_ASSEMBLER_NAME (decl));
  148. #endif /* APPLE_C */
  149. #ifdef APPLE_HAX
  150.   /* Identifying the function's name as a code label need only be done
  151.      if tm.h asks for it. */
  152. #ifdef ASM_FUNCTIONIFY_NAME
  153.   ASM_FUNCTIONIFY_NAME (DECL_ASSEMBLER_NAME (decl));
  154. #endif
  155. #endif /* APPLE_HAX */
  156.  
  157.   if (DECL_RTL (decl) == 0)
  158.     DECL_RTL (decl)
  159.       = gen_rtx (MEM, DECL_MODE (decl),
  160.          gen_rtx (SYMBOL_REF, Pmode, DECL_ASSEMBLER_NAME (decl)));
  161.  
  162.   /* Record at least one function has been defined.  */
  163.   function_defined = 1;
  164. }
  165.  
  166. /* Decode an `asm' spec for a declaration as a register name.
  167.    Return the register number, or -1 if nothing specified,
  168.    or -2 if the name is not a register.  */
  169.  
  170. int
  171. decode_reg_name (asmspec)
  172.      char *asmspec;
  173. {
  174.   if (asmspec != 0)
  175.     {
  176.       int i;
  177.       extern char *reg_names[];
  178.  
  179.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  180.     if (!strcmp (asmspec, reg_names[i]))
  181.       break;
  182.  
  183.       if (i < FIRST_PSEUDO_REGISTER)
  184.     return i;
  185.       else
  186.     return -2;
  187.     }
  188.  
  189.   return -1;
  190. }
  191.  
  192. /* Create the DECL_RTL for a declaration for a static or external variable
  193.    or static or external function.
  194.    ASMSPEC, if not 0, is the string which the user specified
  195.    as the assembler symbol name.
  196.    TOP_LEVEL is nonzero if this is a file-scope variable.
  197.  
  198.    This is never called for PARM_DECL nodes.  */
  199.  
  200. void
  201. make_decl_rtl (decl, asmspec, top_level)
  202.      tree decl;
  203.      char *asmspec;
  204.      int top_level;
  205. {
  206.   register char *name = DECL_ASSEMBLER_NAME (decl);
  207.   int reg_number = decode_reg_name (asmspec);
  208.  
  209.   if (reg_number == -2)
  210.     {
  211.       name = (char *) obstack_alloc (saveable_obstack,
  212.                      strlen (asmspec) + 2);
  213.       name[0] = '*';
  214.       strcpy (&name[1], asmspec);
  215.     }
  216.  
  217.   /* For a duplicate declaration, we can be called twice on the
  218.      same DECL node.  Don't alter the RTL already made
  219.      unless the old mode is wrong (which can happen when
  220.      the previous rtl was made when the type was incomplete).  */
  221.   if (DECL_RTL (decl) == 0
  222.       || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
  223.     {
  224.       DECL_RTL (decl) = 0;
  225.  
  226.       /* First detect errors in declaring global registers.  */
  227.       if (TREE_REGDECL (decl) && reg_number == -1)
  228.     error_with_decl (decl,
  229.              "register name not specified for `%s'");
  230.       else if (TREE_REGDECL (decl) && reg_number == -2)
  231.     error_with_decl (decl,
  232.              "invalid register name for `%s'");
  233.       else if (reg_number >= 0 && ! TREE_REGDECL (decl))
  234.     error_with_decl (decl,
  235.              "register name given for non-register variable `%s'");
  236.       else if (TREE_REGDECL (decl) && TREE_CODE (decl) == FUNCTION_DECL)
  237.     error ("function declared `register'");
  238.       else if (TREE_REGDECL (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
  239.     error_with_decl (decl, "data type of `%s' isn't suitable for a register");
  240.       /* Now handle properly declared static register variables.  */
  241.       else if (TREE_REGDECL (decl))
  242.     {
  243.       int nregs;
  244.       if (pedantic)
  245.         warning ("ANSI C forbids global register variables");
  246.       if (DECL_INITIAL (decl) != 0)
  247.         {
  248.           DECL_INITIAL (decl) = 0;
  249.           error ("global register variable has initial value");
  250.         }
  251.       if (fixed_regs[reg_number] == 0
  252.           && function_defined && top_level)
  253.         error ("global register variable follows a function definition");
  254.       DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
  255.       if (top_level)
  256.         {
  257.           /* Make this register fixed, so not usable for anything else.  */
  258.           nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
  259.           while (nregs > 0)
  260.         global_regs[reg_number + --nregs] = 1;
  261.           init_reg_sets_1 ();
  262.         }
  263.     }
  264.  
  265.       /* Now handle ordinary static variables and functions (in memory).
  266.      Also handle vars declared register invalidly.  */
  267.       if (DECL_RTL (decl) == 0)
  268.     {
  269.       /* Can't use just the variable's own name for a variable
  270.          whose scope is less than the whole file.
  271.          Concatenate a distinguishing number.  */
  272.       if (!top_level && !TREE_EXTERNAL (decl) && asmspec == 0)
  273.         {
  274.           char *label;
  275.  
  276.           ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
  277.           name = obstack_copy0 (saveable_obstack, label, strlen (label));
  278.           var_labelno++;
  279.         }
  280.  
  281. #ifdef APPLE_C
  282.       /* Transform a pascal name to all-upper-case. */
  283.       if (TREE_PASCAL (decl))
  284.         string_upcase (name);
  285.       /* Replace direct function name with its definition (!) */
  286.       if (TREE_DIRECT (decl) && DECL_INITIAL (decl))
  287.         name = build_direct_defn (name, DECL_INITIAL (decl));
  288. #endif /* APPLE_C */
  289. #ifdef APPLE_HAX
  290.       /* Maybe identify data vs code names with a leading character. */
  291. #ifdef ASM_FUNCTIONIFY_NAME
  292.       if (TREE_CODE (decl) == FUNCTION_DECL)
  293.         ASM_FUNCTIONIFY_NAME (name);
  294. #endif
  295. #ifdef ASM_DATIFY_NAME
  296.       if (TREE_CODE (decl) == VAR_DECL)
  297.         ASM_DATIFY_NAME (name);
  298. #endif
  299. #endif /* APPLE_HAX */
  300.  
  301.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
  302.                      gen_rtx (SYMBOL_REF, Pmode, name));
  303.       if (TREE_VOLATILE (decl))
  304.         MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  305.       if (TREE_READONLY (decl))
  306.         RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
  307.       MEM_IN_STRUCT_P (DECL_RTL (decl))
  308.         = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  309.            || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  310.            || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  311.     }
  312.     }
  313. }
  314.  
  315. /* Output a string of literal assembler code
  316.    for an `asm' keyword used between functions.  */
  317.  
  318. void
  319. assemble_asm (string)
  320.      tree string;
  321. {
  322.   app_enable ();
  323.  
  324.   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
  325. }
  326.  
  327. /* Output assembler code associated with defining the name of a function
  328.    as described by DECL.  */
  329.  
  330. void
  331. assemble_function (decl)
  332.      tree decl;
  333. {
  334.   rtx x, n;
  335.   char *fnname;
  336.   int align;
  337.  
  338.   /* Get the function's name, as described by its RTL.
  339.      This may be different from the DECL_NAME name used in the source file.  */
  340.  
  341.   x = DECL_RTL (decl);
  342.   if (GET_CODE (x) != MEM)
  343.     abort ();
  344.   n = XEXP (x, 0);
  345.   if (GET_CODE (n) != SYMBOL_REF)
  346.     abort ();
  347.   fnname = XSTR (n, 0);
  348.  
  349. #ifdef APPLE_HAX
  350.   define_a_function (fnname);
  351.   /* Do any machine/system dependent processing of the function name that
  352.      must be done before anything else is output. */
  353. #ifdef ASM_PREDECLARE_FUNCTION_NAME
  354.   ASM_PREDECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
  355. #endif
  356. #endif /* APPLE_HAX */
  357.  
  358.   /* The following code does not need preprocessing in the assembler.  */
  359.  
  360.   app_disable ();
  361.  
  362.   text_section ();
  363.  
  364. #ifdef SDB_DEBUGGING_INFO
  365.   /* Make sure types are defined for debugger before fcn name is defined.  */
  366.   if (write_symbols == SDB_DEBUG)
  367.     sdbout_tags (gettags ());
  368. #endif
  369.  
  370.   /* Tell assembler to move to target machine's alignment for functions.  */
  371.  
  372.   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  373.   if (align > 0)
  374.     ASM_OUTPUT_ALIGN (asm_out_file, align);
  375.  
  376. #ifdef SDB_DEBUGGING_INFO
  377.   /* Output SDB definition of the function.  */
  378.   if (write_symbols == SDB_DEBUG)
  379.     sdbout_mark_begin_function ();
  380. #endif
  381.  
  382.   /* Make function name accessible from other files, if appropriate.  */
  383.  
  384.   if (TREE_PUBLIC (decl))
  385.     ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
  386.  
  387.   /* Do any machine/system dependent processing of the function name */
  388. #ifdef ASM_DECLARE_FUNCTION_NAME
  389.   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
  390. #else
  391.   /* Standard thing is just output label for the function.  */
  392.   ASM_OUTPUT_LABEL (asm_out_file, fnname);
  393. #endif /* ASM_DECLARE_FUNCTION_NAME */
  394. }
  395.  
  396. /* Assemble " .int 0\n" or whatever this assembler wants.  */
  397.  
  398. void
  399. assemble_integer_zero ()
  400. {
  401.   ASM_OUTPUT_INT (asm_out_file, const0_rtx);
  402. }
  403.  
  404. /* Assemble a string constant with the specified C string as contents.  */
  405.  
  406. void
  407. assemble_string (p, size)
  408.      unsigned char *p;
  409.      int size;
  410. {
  411.   register int i;
  412.   int excess = 0;
  413.   int pos = 0;
  414.   int maximum = 2000;
  415.  
  416.   /* If the string is very long, split it up.  */
  417.  
  418.   while (pos < size)
  419.     {
  420.       int thissize = size - pos;
  421.       if (thissize > maximum)
  422.     thissize = maximum;
  423.  
  424. #ifdef ASM_OUTPUT_ASCII
  425.       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
  426. #else
  427.       fprintf (asm_out_file, "\t.ascii \"");
  428.  
  429.       for (i = 0; i < thissize; i++)
  430.     {
  431.       register int c = p[i];
  432.       if (c == '\"' || c == '\\')
  433.         putc ('\\', asm_out_file);
  434.       if (c >= ' ' && c < 0177)
  435.         putc (c, asm_out_file);
  436.       else
  437.         {
  438.           fprintf (asm_out_file, "\\%o", c);
  439.           /* After an octal-escape, if a digit follows,
  440.          terminate one string constant and start another.
  441.          The Vax assembler fails to stop reading the escape
  442.          after three digits, so this is the only way we
  443.          can get it to parse the data properly.  */
  444.           if (i < thissize - 1
  445.           && p[i + 1] >= '0' && p[i + 1] <= '9')
  446.         fprintf (asm_out_file, "\"\n\t.ascii \"");
  447.         }
  448.     }
  449.       fprintf (asm_out_file, "\"\n");
  450. #endif /* no ASM_OUTPUT_ASCII */
  451.  
  452.       pos += thissize;
  453.       p += thissize;
  454.     }
  455. }
  456.  
  457. /* Assemble everything that is needed for a variable or function declaration.
  458.    Not used for automatic variables, and not used for function definitions.
  459.    Should not be called for variables of incomplete structure type.
  460.  
  461.    TOP_LEVEL is nonzero if this variable has file scope.
  462.    WRITE_SYMBOLS is DBX_DEBUG if writing dbx symbol output.
  463.    The dbx data for a file-scope variable is written here.
  464.    AT_END is nonzero if this is the special handling, at end of compilation,
  465.    to define things that have had only tentative definitions.  */
  466.  
  467. void
  468. assemble_variable (decl, top_level, write_symbols, at_end)
  469.      tree decl;
  470.      int top_level;
  471.      enum debugger write_symbols;
  472.      int at_end;
  473. {
  474.   register char *name;
  475.   register int i;
  476.  
  477.   /* Do nothing for global register variables.  */
  478.  
  479.   if (GET_CODE (DECL_RTL (decl)) == REG)
  480.     return;
  481.  
  482.   /* Normally no need to say anything for external references,
  483.      since assembler considers all undefined symbols external.  */
  484.  
  485.   if (TREE_EXTERNAL (decl))
  486.     return;
  487.  
  488.   /* Output no assembler code for a function declaration.
  489.      Only definitions of functions output anything.  */
  490.  
  491.   if (TREE_CODE (decl) == FUNCTION_DECL)
  492.     return;
  493.  
  494.   /* If type was incomplete when the variable was declared,
  495.      see if it is complete now.  */
  496.  
  497.   if (DECL_SIZE (decl) == 0)
  498.     layout_decl (decl, 0);
  499.  
  500.   /* Still incomplete => don't allocate it; treat the tentative defn
  501.      (which is what it must have been) as an `extern' reference.  */
  502.  
  503.   if (DECL_SIZE (decl) == 0)
  504.     {
  505.       error_with_file_and_line (DECL_SOURCE_FILE (decl),
  506.                 DECL_SOURCE_LINE (decl),
  507.                 "storage size of static var `%s' isn't known",
  508.                 IDENTIFIER_POINTER (DECL_NAME (decl)));
  509.       return;
  510.     }
  511.  
  512.   /* The first declaration of a variable that comes through this function
  513.      decides whether it is global (in C, has external linkage)
  514.      or local (in C, has internal linkage).  So do nothing more
  515.      if this function has already run.  */
  516.  
  517.   if (TREE_ASM_WRITTEN (decl))
  518.     return;
  519.  
  520.   TREE_ASM_WRITTEN (decl) = 1;
  521.  
  522. #ifdef DBX_DEBUGGING_INFO
  523.   /* File-scope global variables are output here.  */
  524.   if (write_symbols == DBX_DEBUG && top_level)
  525.     dbxout_symbol (decl, 0);
  526. #endif
  527. #ifdef SDB_DEBUGGING_INFO
  528.   if (write_symbols == SDB_DEBUG && top_level)
  529.     sdbout_symbol (decl, 0);
  530. #endif
  531.   if (write_symbols == GDB_DEBUG)
  532.     /* Make sure the file is known to GDB even if it has no functions.  */
  533.     set_current_gdbfile (DECL_SOURCE_FILE (decl));
  534.  
  535.   /* If storage size is erroneously variable, just continue.
  536.      Error message was already made.  */
  537.  
  538.   if (! TREE_LITERAL (DECL_SIZE (decl)))
  539.     return;
  540.  
  541.   app_disable ();
  542.  
  543.   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  544.  
  545.   /* Handle uninitialized definitions.  */
  546.  
  547.   if (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
  548.     {
  549.       int size = (TREE_INT_CST_LOW (DECL_SIZE (decl))
  550.           * DECL_SIZE_UNIT (decl)
  551.           / BITS_PER_UNIT);
  552.       int rounded = size;
  553.       /* Don't allocate zero bytes of common,
  554.      since that means "undefined external" in the linker.  */
  555.       if (size == 0) rounded = 1;
  556.       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  557.      so that each uninitialized object starts on such a boundary.  */
  558.       rounded = ((rounded + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  559.          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  560.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  561.       if (flag_shared_data)
  562.     data_section ();
  563.       if (TREE_PUBLIC (decl))
  564.     ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
  565.       else
  566.     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  567.       return;
  568.     }
  569.  
  570.   /* Handle initialized definitions.  */
  571.  
  572.   /* First make the assembler name(s) global if appropriate.  */
  573.   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
  574.     ASM_GLOBALIZE_LABEL (asm_out_file, name);
  575. #if 0
  576.   for (d = equivalents; d; d = TREE_CHAIN (d))
  577.     {
  578.       tree e = TREE_VALUE (d);
  579.       if (TREE_PUBLIC (e) && DECL_NAME (e))
  580.     ASM_GLOBALIZE_LABEL (asm_out_file,
  581.                  XSTR (XEXP (DECL_RTL (e), 0), 0));
  582.     }
  583. #endif
  584.  
  585.   /* Output any data that we will need to use the address of.  */
  586.   if (DECL_INITIAL (decl))
  587.     output_addressed_constants (DECL_INITIAL (decl));
  588.  
  589. #ifdef APPLE_HAX
  590.   define_a_variable (name);
  591.   /* Do any machine/system dependent processing of the variable name. */
  592. #ifdef ASM_DECLARE_VARIABLE_NAME
  593.   ASM_DECLARE_VARIABLE_NAME (asm_out_file, name, TREE_PUBLIC (decl));
  594. #endif
  595. #endif /* APPLE_HAX */
  596.  
  597.   /* Switch to the proper section for this data.  */
  598. #ifdef SELECT_SECTION
  599.   SELECT_SECTION (decl);
  600. #else
  601.   if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
  602.     text_section ();
  603.   else
  604.     data_section ();
  605. #endif
  606.  
  607.   /* Output the alignment of this data.  */
  608.   for (i = 0; DECL_ALIGN (decl) >= BITS_PER_UNIT << (i + 1); i++);
  609.   if (i > 0)
  610.     ASM_OUTPUT_ALIGN (asm_out_file, i);
  611.  
  612.   /* Output the name(s) of this data.  */
  613.   ASM_OUTPUT_LABEL (asm_out_file, name);
  614. #if 0
  615.   for (d = equivalents; d; d = TREE_CHAIN (d))
  616.     {
  617.       tree e = TREE_VALUE (d);
  618.       ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
  619.     }
  620. #endif
  621.  
  622.   if (DECL_INITIAL (decl))
  623.     /* Output the actual data.  */
  624.     output_constant (DECL_INITIAL (decl), int_size_in_bytes (TREE_TYPE (decl)));
  625.   else
  626.     /* Leave space for it.  */
  627.     ASM_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (decl)));
  628. #ifdef APPLE_HAX
  629.   /* Maybe do something to close out the definition of a variable. */
  630. #ifdef ASM_VARIABLE_END
  631.   ASM_VARIABLE_END (asm_out_file, name);
  632. #endif
  633. #endif /* APPLE_HAX */
  634. }
  635.  
  636. /* Output something to declare an external symbol to the assembler.
  637.    (Most assemblers don't need this, so we normally output nothing.)  */
  638.  
  639. void
  640. assemble_external (decl)
  641.      tree decl;
  642. {
  643.   rtx rtl = DECL_RTL (decl);
  644.  
  645.   if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  646.     {
  647. #ifdef ASM_OUTPUT_EXTERNAL
  648.       /* Some systems do require some output.  */
  649.       ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
  650. #endif
  651.     }
  652. }
  653.  
  654. /* Output to FILE a reference to the assembler name of a C-level name NAME.
  655.    If NAME starts with a *, the rest of NAME is output verbatim.
  656.    Otherwise NAME is transformed in an implementation-defined way
  657.    (usually by the addition of an underscore).
  658.    Many macros in the tm file are defined to call this function.  */
  659.  
  660. void
  661. assemble_name (file, name)
  662.      FILE *file;
  663.      char *name;
  664. {
  665.   if (name[0] == '*')
  666.     fputs (&name[1], file);
  667.   else
  668.     ASM_OUTPUT_LABELREF (file, name);
  669. }
  670.  
  671. /* Allocate SIZE bytes writable static space with a gensym name
  672.    and return an RTX to refer to its address.  */
  673.  
  674. rtx
  675. assemble_static_space (size)
  676.      int size;
  677. {
  678.   char name[12];
  679.   char *namestring;
  680.   rtx x;
  681.   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  682.      so that each uninitialized object starts on such a boundary.  */
  683.   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  684.          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  685.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  686.  
  687.   if (flag_shared_data)
  688.     data_section ();
  689.   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
  690.   ++const_labelno;
  691.  
  692.   namestring = (char *) obstack_alloc (saveable_obstack,
  693.                        strlen (name) + 2);
  694.   strcpy (namestring, name);
  695.  
  696.   x = gen_rtx (SYMBOL_REF, Pmode, namestring);
  697.   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  698.   return x;
  699. }
  700.  
  701. /* Here we combine duplicate floating constants to make
  702.    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
  703.  
  704. /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
  705.    They are chained through the CONST_DOUBLE_CHAIN.
  706.    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
  707.    In that case, CONST_DOUBLE_MEM is either a MEM,
  708.    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.  */
  709.  
  710. static rtx real_constant_chain;
  711.  
  712. /* Return a CONST_DOUBLE for a value specified as a pair of ints.
  713.    For an integer, I0 is the low-order word and I1 is the high-order word.
  714.    For a real number, I0 is the word with the low address
  715.    and I1 is the word with the high address.  */
  716.  
  717. rtx
  718. immed_double_const (i0, i1, mode)
  719.      int i0, i1;
  720.      enum machine_mode mode;
  721. {
  722.   register rtx r;
  723.  
  724.   if (mode == DImode && i0 == 0 && i1 == 0)
  725.     return const0_rtx;
  726.  
  727.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  728.      If one is found, return it.  */
  729.  
  730.   for (r = real_constant_chain; r; r = CONST_DOUBLE_CHAIN (r))
  731.     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
  732.     && GET_MODE (r) == mode)
  733.       return r;
  734.  
  735.   /* No; make a new one and add it to the chain.  */
  736.  
  737.   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
  738.  
  739.   CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  740.   real_constant_chain = r;
  741.  
  742.   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
  743.      Actual use of mem-slot is only through force_const_double_mem.  */
  744.  
  745.   CONST_DOUBLE_MEM (r) = const0_rtx;
  746.  
  747.   return r;
  748. }
  749.  
  750. /* Return a CONST_DOUBLE for a specified `double' value
  751.    and machine mode.  */
  752.  
  753. rtx
  754. immed_real_const_1 (d, mode)
  755.      REAL_VALUE_TYPE d;
  756.      enum machine_mode mode;
  757. {
  758.   union real_extract u;
  759.   register rtx r;
  760.   REAL_VALUE_TYPE negated;
  761.  
  762.   /* Get the desired `double' value as a sequence of ints
  763.      since that is how they are stored in a CONST_DOUBLE.  */
  764.  
  765.   u.d = d;
  766.  
  767.   /* Detect zero.  */
  768.  
  769.   negated = REAL_VALUE_NEGATE (d);
  770.   if (REAL_VALUES_EQUAL (negated, d))
  771. #ifdef APPLE_HAX
  772.     /* Return the correct zero rtx for all float modes including XF. */
  773.     return (CONST0_RTX (mode));
  774. #else
  775.     return (mode == DFmode ? dconst0_rtx : fconst0_rtx);
  776. #endif /* APPLE_HAX */
  777.  
  778.   if (sizeof u == 2 * sizeof (int))
  779.     return immed_double_const (u.i[0], u.i[1], mode);
  780.  
  781.   /* The rest of this function handles the case where
  782.      a float value requires more than 2 ints of space.
  783.      It will be deleted as dead code on machines that don't need it.  */
  784.  
  785.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  786.      If one is found, return it.  */
  787.  
  788.   for (r = real_constant_chain; r; r = CONST_DOUBLE_CHAIN (r))
  789.     if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
  790.     && GET_MODE (r) == mode)
  791.       return r;
  792.  
  793.   /* No; make a new one and add it to the chain.  */
  794.  
  795.   r = rtx_alloc (CONST_DOUBLE);
  796.   PUT_MODE (r, mode);
  797.   bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
  798.  
  799.   CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  800.   real_constant_chain = r;
  801.  
  802.   /* Store const0_rtx in slot 2 since this CONST_DOUBLE is on the chain.
  803.      Actual use of slot 2 is only through force_const_double_mem.  */
  804.  
  805.   CONST_DOUBLE_MEM (r) = const0_rtx;
  806.  
  807.   return r;
  808. }
  809.  
  810. /* Return a CONST_DOUBLE rtx for a value specified by EXP,
  811.    which must be a REAL_CST tree node.  */
  812.  
  813. rtx
  814. immed_real_const (exp)
  815.      tree exp;
  816. {
  817.   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
  818. }
  819.  
  820. /* Given a CONST_DOUBLE, cause a constant in memory to be created
  821.    (unless we already have one for the same value)
  822.    and return a MEM rtx to refer to it.
  823.    Put the CONST_DOUBLE on real_constant_chain if it isn't already there.  */
  824.  
  825. rtx
  826. force_const_double_mem (r)
  827.      rtx r;
  828. {
  829.   if (CONST_DOUBLE_MEM (r) == cc0_rtx)
  830.     {
  831.       CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  832.       real_constant_chain = r;
  833.       CONST_DOUBLE_MEM (r) = const0_rtx;
  834.     }
  835.  
  836.   if (CONST_DOUBLE_MEM (r) == const0_rtx)
  837.     {
  838.       CONST_DOUBLE_MEM (r) = force_const_mem (GET_MODE (r), r);
  839.     }
  840.   /* CONST_DOUBLE_MEM (r) is now a MEM with a constant address.
  841.      If that is legitimate, return it.
  842.      Othewise it will need reloading, so return a copy of it.  */
  843.   if (memory_address_p (GET_MODE (r), XEXP (CONST_DOUBLE_MEM (r), 0)))
  844.     return CONST_DOUBLE_MEM (r);
  845.   return gen_rtx (MEM, GET_MODE (r), XEXP (CONST_DOUBLE_MEM (r), 0));
  846. }
  847.  
  848. /* At the end of a function, forget the memory-constants
  849.    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
  850.    Also clear out real_constant_chain and clear out all the chain-pointers.  */
  851.  
  852. void
  853. clear_const_double_mem ()
  854. {
  855.   register rtx r, next;
  856.  
  857.   for (r = real_constant_chain; r; r = next)
  858.     {
  859.       next = CONST_DOUBLE_CHAIN (r);
  860.       CONST_DOUBLE_CHAIN (r) = 0;
  861.       CONST_DOUBLE_MEM (r) = cc0_rtx;
  862.     }
  863.   real_constant_chain = 0;
  864. }
  865.  
  866. /* Given an expression EXP with a constant value,
  867.    reduce it to the sum of an assembler symbol and an integer.
  868.    Store them both in the structure *VALUE.
  869.    Abort if EXP does not reduce.  */
  870.  
  871. struct addr_const
  872. {
  873.   rtx base;
  874.   int offset;
  875. };
  876.  
  877. static void
  878. decode_addr_const (exp, value)
  879.      tree exp;
  880.      struct addr_const *value;
  881. {
  882.   register tree target = TREE_OPERAND (exp, 0);
  883.   register int offset = 0;
  884.   register rtx x;
  885.  
  886.   while (1)
  887.     {
  888.       if (TREE_CODE (target) == COMPONENT_REF)
  889.     {
  890.       offset += DECL_OFFSET (TREE_OPERAND (target, 1)) / BITS_PER_UNIT;
  891.       target = TREE_OPERAND (target, 0);
  892.     }
  893.       else if (TREE_CODE (target) == ARRAY_REF)
  894.     {
  895.       if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
  896.           || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
  897.         abort ();
  898.       offset += ((TYPE_SIZE_UNIT (TREE_TYPE (target))
  899.               * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
  900.               * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
  901.              / BITS_PER_UNIT);
  902.       target = TREE_OPERAND (target, 0);
  903.     }
  904.       else break;
  905.     }
  906.  
  907.   if (TREE_CODE (target) == VAR_DECL
  908.       || TREE_CODE (target) == FUNCTION_DECL)
  909.     x = DECL_RTL (target);
  910.   else if (TREE_LITERAL (target))
  911.     x = TREE_CST_RTL (target);
  912.   else
  913.     abort ();
  914.  
  915.   if (GET_CODE (x) != MEM)
  916.     abort ();
  917.   x = XEXP (x, 0);
  918.  
  919.   value->base = x;
  920.   value->offset = offset;
  921. }
  922.  
  923. /* Uniquize all constants that appear in memory.
  924.    Each constant in memory thus far output is recorded
  925.    in `const_hash_table' with a `struct constant_descriptor'
  926.    that contains a polish representation of the value of
  927.    the constant.
  928.  
  929.    We cannot store the trees in the hash table
  930.    because the trees may be temporary.  */
  931.  
  932. struct constant_descriptor
  933. {
  934.   struct constant_descriptor *next;
  935.   char *label;
  936.   char contents[1];
  937. };
  938.  
  939. #define HASHBITS 30
  940. #define MAX_HASH_TABLE 1007
  941. static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
  942.  
  943. #ifdef APPLE_HAX
  944. /* For machines with modules, want to be able to clear out the whole table. */
  945.  
  946. clear_const_hash_table ()
  947. {
  948.   int i;
  949.  
  950.   for (i = 0; i < MAX_HASH_TABLE; ++i)
  951.     const_hash_table[i] = NULL;
  952. }
  953. #endif /* APPLE_HAX */
  954.  
  955. /* Compute a hash code for a constant expression.  */
  956.  
  957. int
  958. const_hash (exp)
  959.      tree exp;
  960. {
  961.   register char *p;
  962.   register int len, hi, i;
  963.   register enum tree_code code = TREE_CODE (exp);
  964.  
  965.   if (code == INTEGER_CST)
  966.     {
  967.       p = (char *) &TREE_INT_CST_LOW (exp);
  968.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  969.     }
  970.   else if (code == REAL_CST)
  971.     {
  972.       p = (char *) &TREE_REAL_CST (exp);
  973.       len = sizeof TREE_REAL_CST (exp);
  974.     }
  975.   else if (code == STRING_CST)
  976.     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
  977.   else if (code == COMPLEX_CST)
  978.     return const_hash (TREE_REALPART (exp)) * 5
  979.       + const_hash (TREE_IMAGPART (exp));
  980.   else if (code == CONSTRUCTOR)
  981.     {
  982.       register tree link;
  983.  
  984.       /* For record type, include the type in the hashing.
  985.      We do not do so for array types
  986.      because (1) the sizes of the elements are sufficient
  987.      and (2) distinct array types can have the same constructor.  */
  988.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  989.     hi = ((int) TREE_TYPE (exp) & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
  990.       else
  991.     hi = 5;
  992.  
  993.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  994.     hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
  995.  
  996.       return hi;
  997.     }
  998.   else if (code == ADDR_EXPR)
  999.     {
  1000.       struct addr_const value;
  1001.       decode_addr_const (exp, &value);
  1002.       p = (char *) &value;
  1003.       len = sizeof value;
  1004.     }
  1005.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1006.     return const_hash (TREE_OPERAND (exp, 0)) * 9
  1007.       +  const_hash (TREE_OPERAND (exp, 1));
  1008.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1009.     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
  1010.  
  1011.   /* Compute hashing function */
  1012.   hi = len;
  1013.   for (i = 0; i < len; i++)
  1014.     hi = ((hi * 613) + (unsigned)(p[i]));
  1015.  
  1016.   hi &= (1 << HASHBITS) - 1;
  1017.   hi %= MAX_HASH_TABLE;
  1018.   return hi;
  1019. }
  1020.  
  1021. /* Compare a constant expression EXP with a constant-descriptor DESC.
  1022.    Return 1 if DESC describes a constant with the same value as EXP.  */
  1023.  
  1024. static int
  1025. compare_constant (exp, desc)
  1026.      tree exp;
  1027.      struct constant_descriptor *desc;
  1028. {
  1029.   return 0 != compare_constant_1 (exp, desc->contents);
  1030. }
  1031.  
  1032. /* Compare constant expression EXP with a substring P of a constant descriptor.
  1033.    If they match, return a pointer to the end of the substring matched.
  1034.    If they do not match, return 0.
  1035.  
  1036.    Since descriptors are written in polish prefix notation,
  1037.    this function can be used recursively to test one operand of EXP
  1038.    against a subdescriptor, and if it succeeds it returns the
  1039.    address of the subdescriptor for the next operand.  */
  1040.  
  1041. static char *
  1042. compare_constant_1 (exp, p)
  1043.      tree exp;
  1044.      char *p;
  1045. {
  1046.   register char *strp;
  1047.   register int len;
  1048.   register enum tree_code code = TREE_CODE (exp);
  1049.  
  1050. #ifdef MPW_C31
  1051.   /* This appears to screw up even when enum is int-sized. */
  1052.   if (code != (unsigned int) *p++)
  1053. #else
  1054.   if (code != (enum tree_code) *p++)
  1055. #endif /* MPW_C31 */
  1056.     return 0;
  1057.  
  1058.   if (code == INTEGER_CST)
  1059.     {
  1060.       /* Integer constants are the same only if the same width of type.  */
  1061.       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
  1062.     return 0;
  1063.       strp = (char *) &TREE_INT_CST_LOW (exp);
  1064.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1065.     }
  1066.   else if (code == REAL_CST)
  1067.     {
  1068.       /* Real constants are the same only if the same width of type.  */
  1069.       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
  1070.     return 0;
  1071.       strp = (char *) &TREE_REAL_CST (exp);
  1072.       len = sizeof TREE_REAL_CST (exp);
  1073.     }
  1074.   else if (code == STRING_CST)
  1075.     {
  1076.       if (flag_writable_strings)
  1077.     return 0;
  1078.       strp = TREE_STRING_POINTER (exp);
  1079.       len = TREE_STRING_LENGTH (exp);
  1080.       if (bcmp (&TREE_STRING_LENGTH (exp), p,
  1081.         sizeof TREE_STRING_LENGTH (exp)))
  1082.     return 0;
  1083.       p += sizeof TREE_STRING_LENGTH (exp);
  1084.     }
  1085.   else if (code == COMPLEX_CST)
  1086.     {
  1087.       p = compare_constant_1 (TREE_REALPART (exp), p);
  1088.       if (p == 0) return 0;
  1089.       p = compare_constant_1 (TREE_IMAGPART (exp), p);
  1090.       return p;
  1091.     }
  1092.   else if (code == CONSTRUCTOR)
  1093.     {
  1094.       register tree link;
  1095.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1096.       tree type;
  1097.  
  1098.       if (bcmp (&length, p, sizeof length))
  1099.     return 0;
  1100.       p += sizeof length;
  1101.  
  1102.       /* For record constructors, insist that the types match.
  1103.      For arrays, just verify both constructors are for arrays.  */
  1104.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1105.     type = TREE_TYPE (exp);
  1106.       else
  1107.     type = 0;
  1108.       if (bcmp (&type, p, sizeof type))
  1109.     return 0;
  1110.       p += sizeof type;
  1111.  
  1112.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1113.     if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
  1114.       return 0;
  1115.       return p;
  1116.     }
  1117.   else if (code == ADDR_EXPR)
  1118.     {
  1119.       struct addr_const value;
  1120.       decode_addr_const (exp, &value);
  1121.       strp = (char *) &value;
  1122.       len = sizeof value;
  1123.       /* Compare SYMBOL_REF address and offset.  */
  1124.       while (--len >= 0)
  1125.     if (*p++ != *strp++)
  1126.       return 0;
  1127.       /* Compare symbol name.  */
  1128.       strp = XSTR (value.base, 0);
  1129.       len = strlen (strp) + 1;
  1130.     }
  1131.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1132.     {
  1133.       if (*p++ != (char) code)
  1134.     return 0;
  1135.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1136.       if (p == 0) return 0;
  1137.       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
  1138.       return p;
  1139.     }
  1140.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1141.     {
  1142.       if (*p++ != (char) code)
  1143.     return 0;
  1144.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1145.       return p;
  1146.     }
  1147.  
  1148.   /* Compare constant contents.  */
  1149.   while (--len >= 0)
  1150.     if (*p++ != *strp++)
  1151.       return 0;
  1152.  
  1153.   return p;
  1154. }
  1155.  
  1156. /* Construct a constant descriptor for the expression EXP.
  1157.    It is up to the caller to enter the descriptor in the hash table.  */
  1158.  
  1159. static struct constant_descriptor *
  1160. record_constant (exp)
  1161.      tree exp;
  1162. {
  1163.   struct constant_descriptor *ptr = 0;
  1164.   int buf;
  1165.  
  1166.   obstack_grow (&permanent_obstack, &ptr, sizeof ptr);
  1167.   obstack_grow (&permanent_obstack, &buf, sizeof buf);
  1168.   record_constant_1 (exp);
  1169.   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
  1170. }
  1171.  
  1172. /* Add a description of constant expression EXP
  1173.    to the object growing in `permanent_obstack'.
  1174.    No need to return its address; the caller will get that
  1175.    from the obstack when the object is complete.  */
  1176.  
  1177. static void
  1178. record_constant_1 (exp)
  1179.      tree exp;
  1180. {
  1181.   register char *strp;
  1182.   register int len;
  1183.   register enum tree_code code = TREE_CODE (exp);
  1184.  
  1185.   obstack_1grow (&permanent_obstack, (unsigned int) code);
  1186.  
  1187.   if (code == INTEGER_CST)
  1188.     {
  1189.       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
  1190.       strp = (char *) &TREE_INT_CST_LOW (exp);
  1191.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1192.     }
  1193.   else if (code == REAL_CST)
  1194.     {
  1195.       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
  1196.       strp = (char *) &TREE_REAL_CST (exp);
  1197.       len = sizeof TREE_REAL_CST (exp);
  1198.     }
  1199.   else if (code == STRING_CST)
  1200.     {
  1201.       if (flag_writable_strings)
  1202.     return;
  1203.       strp = TREE_STRING_POINTER (exp);
  1204.       len = TREE_STRING_LENGTH (exp);
  1205.       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
  1206.             sizeof TREE_STRING_LENGTH (exp));
  1207.     }
  1208.   else if (code == COMPLEX_CST)
  1209.     {
  1210.       record_constant_1 (TREE_REALPART (exp));
  1211.       record_constant_1 (TREE_IMAGPART (exp));
  1212.       return;
  1213.     }
  1214.   else if (code == CONSTRUCTOR)
  1215.     {
  1216.       register tree link;
  1217.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1218.       tree type;
  1219.  
  1220.       obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
  1221.  
  1222.       /* For record constructors, insist that the types match.
  1223.      For arrays, just verify both constructors are for arrays.  */
  1224.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1225.     type = TREE_TYPE (exp);
  1226.       else
  1227.     type = 0;
  1228.       obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
  1229.  
  1230.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1231.     record_constant_1 (TREE_VALUE (link));
  1232.       return;
  1233.     }
  1234.   else if (code == ADDR_EXPR)
  1235.     {
  1236.       struct addr_const value;
  1237.       decode_addr_const (exp, &value);
  1238.       /* Record the SYMBOL_REF address and the offset.  */
  1239.       obstack_grow (&permanent_obstack, (char *) &value, sizeof value);
  1240.       /* Record the symbol name.  */
  1241.       obstack_grow (&permanent_obstack, XSTR (value.base, 0),
  1242.             strlen (XSTR (value.base, 0)) + 1);
  1243.       return;
  1244.     }
  1245.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1246.     {
  1247.       obstack_1grow (&permanent_obstack, (int) code);
  1248.       record_constant_1 (TREE_OPERAND (exp, 0));
  1249.       record_constant_1 (TREE_OPERAND (exp, 1));
  1250.       return;
  1251.     }
  1252.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1253.     {
  1254.       obstack_1grow (&permanent_obstack, (int) code);
  1255.       record_constant_1 (TREE_OPERAND (exp, 0));
  1256.       return;
  1257.     }
  1258.  
  1259.   /* Record constant contents.  */
  1260.   obstack_grow (&permanent_obstack, strp, len);
  1261. }
  1262.  
  1263. /* Return the constant-label-string for constant value EXP.
  1264.    If no constant equal to EXP has yet been output,
  1265.    define a new label and output assembler code for it.
  1266.    The const_hash_table records which constants already have label strings.  */
  1267.  
  1268. static char *
  1269. get_or_assign_label (exp)
  1270.      tree exp;
  1271. {
  1272.   register int hash, i, align;
  1273.   register struct constant_descriptor *desc;
  1274.   char label[256];
  1275.  
  1276.   /* Make sure any other constants whose addresses appear in EXP
  1277.      are assigned label numbers.  */
  1278.  
  1279.   output_addressed_constants (exp);
  1280.  
  1281.   /* Compute hash code of EXP.  Search the descriptors for that hash code
  1282.      to see if any of them describes EXP.  If yes, the descriptor records
  1283.      the label number already assigned.  */
  1284.  
  1285.   hash = const_hash (exp) % MAX_HASH_TABLE;
  1286.  
  1287.   for (desc = const_hash_table[hash]; desc; desc = desc->next)
  1288.     if (compare_constant (exp, desc))
  1289. #ifdef APPLE_HAX
  1290.       /* The name is defined in a previously-existing module, so it
  1291.      needs to go on the current import list. */
  1292.       {
  1293.     import_a_variable (desc->label);
  1294. #ifdef TARGET_BSTR
  1295.     if (TARGET_BSTR
  1296.         && TREE_CODE (exp) == STRING_CST
  1297.         && current_function_decl)
  1298.       define_a_variable (desc->label);
  1299. #endif
  1300.     return desc->label;
  1301.       }
  1302. #else
  1303.       return desc->label;
  1304. #endif /* APPLE_HAX */
  1305.  
  1306.   /* No constant equal to EXP is known to have been output.
  1307.      Make a constant descriptor to enter EXP in the hash table.
  1308.      Assign the label number and record it in the descriptor for
  1309.      future calls to this function to find.  */
  1310.  
  1311.   desc = record_constant (exp);
  1312.   desc->next = const_hash_table[hash];
  1313.   const_hash_table[hash] = desc;
  1314.  
  1315.   /* Now output assembler code to define that label
  1316.      and follow it with the data of EXP.  */
  1317.  
  1318. #ifdef APPLE_HAX
  1319.   /* Hook for declaring constants that need to be handled specially. */
  1320. #ifdef ASM_DECLARE_CONSTANT_NAME
  1321.   ASM_DECLARE_CONSTANT_NAME (asm_out_file, const_labelno, exp);
  1322. #endif
  1323. #endif /* APPLE_HAX */
  1324.  
  1325.   /* First switch to text section, except for writable strings.  */
  1326. #ifdef SELECT_SECTION
  1327.   SELECT_SECTION (exp);
  1328. #else
  1329.   if ((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
  1330.     data_section ();
  1331.   else
  1332.     text_section ();
  1333. #endif
  1334.  
  1335. #ifdef APPLE_HAX
  1336.   /* Hook for declaring constants that need to be handled specially. */
  1337. #ifdef ASM_ENTRY_CONSTANT_NAME
  1338.   ASM_ENTRY_CONSTANT_NAME (asm_out_file, const_labelno, exp);
  1339. #endif
  1340. #endif /* APPLE_HAX */
  1341.  
  1342.   /* Align the location counter as required by EXP's data type.  */
  1343. #ifdef CONSTANT_ALIGNMENT
  1344.   align = CONSTANT_ALIGNMENT (TREE_CODE (exp), TYPE_ALIGN (TREE_TYPE (exp)));
  1345. #else
  1346.   align = TYPE_ALIGN (TREE_TYPE (exp));
  1347. #endif
  1348.  
  1349.   for (i = 0; align >= BITS_PER_UNIT << (i + 1); i++);
  1350.   if (i > 0)
  1351.     ASM_OUTPUT_ALIGN (asm_out_file, i);
  1352.  
  1353.   /* Output the label itself.  */
  1354. #ifdef APPLE_HAX
  1355. #ifdef OUTPUT_LABELED_CONSTANT
  1356.   OUTPUT_LABELED_CONSTANT (asm_out_file, const_labelno, exp);
  1357. #else
  1358.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1359.  
  1360.   /* Output the value of EXP.  */
  1361.   output_constant (exp,
  1362.            (TREE_CODE (exp) == STRING_CST
  1363.             ? TREE_STRING_LENGTH (exp)
  1364.             : int_size_in_bytes (TREE_TYPE (exp))));
  1365. #endif
  1366. #else
  1367.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1368.  
  1369.   /* Output the value of EXP.  */
  1370.   output_constant (exp,
  1371.            (TREE_CODE (exp) == STRING_CST
  1372.             ? TREE_STRING_LENGTH (exp)
  1373.             : int_size_in_bytes (TREE_TYPE (exp))));
  1374. #endif /* APPLE_HAX */
  1375.   
  1376. #ifdef APPLE_HAX
  1377.   /* Hook to close out this constant. */
  1378. #ifdef ASM_CONSTANT_END
  1379.   ASM_CONSTANT_END (asm_out_file, const_labelno, exp);
  1380. #endif
  1381. #endif /* APPLE_HAX */
  1382.   /* Create a string containing the label name, in LABEL.  */
  1383.   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1384.   ++const_labelno;
  1385.  
  1386.   desc->label
  1387.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  1388.  
  1389. #ifdef APPLE_HAX
  1390.   /* Make this label imported into the module we're really building. */
  1391. #ifdef REMEMBER_CONSTANT_LABEL
  1392.   REMEMBER_CONSTANT_LABEL (desc->label, exp);
  1393.   import_a_variable (desc->label);
  1394. #endif
  1395. #endif /* APPLE_HAX */
  1396.   return desc->label;
  1397. }
  1398.  
  1399. /* Return an rtx representing a reference to constant data in memory
  1400.    for the constant expression EXP.
  1401.    If assembler code for such a constant has already been output,
  1402.    return an rtx to refer to it.
  1403.    Otherwise, output such a constant in memory and generate
  1404.    an rtx for it.  The TREE_CST_RTL of EXP is set up to point to that rtx.  */
  1405.  
  1406. rtx
  1407. output_constant_def (exp)
  1408.      tree exp;
  1409. {
  1410.   register rtx def;
  1411.   int temp_p = allocation_temporary_p ();
  1412.  
  1413.   if (TREE_CODE (exp) == INTEGER_CST)
  1414.     abort ();            /* No TREE_CST_RTL slot in these.  */
  1415.  
  1416.   if (TREE_CST_RTL (exp))
  1417.     return TREE_CST_RTL (exp);
  1418.  
  1419.   if (TREE_PERMANENT (exp))
  1420.     end_temporary_allocation ();
  1421.  
  1422.   def = gen_rtx (SYMBOL_REF, Pmode, get_or_assign_label (exp));
  1423.  
  1424.   TREE_CST_RTL (exp)
  1425.     = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
  1426.   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
  1427.  
  1428.   if (temp_p && TREE_PERMANENT (exp))
  1429.     resume_temporary_allocation ();
  1430.  
  1431.   return TREE_CST_RTL (exp);
  1432. }
  1433.  
  1434. /* Similar hash facility for making memory-constants
  1435.    from constant rtl-expressions.  It is used on RISC machines
  1436.    where immediate integer arguments and constant addresses are restricted
  1437.    so that such constants must be stored in memory.
  1438.  
  1439.    This pool of constants is reinitialized for each function
  1440.    so each function gets its own constants-pool that comes right before it.  */
  1441.  
  1442. #define MAX_RTX_HASH_TABLE 61
  1443. static struct constant_descriptor *const_rtx_hash_table[MAX_RTX_HASH_TABLE];
  1444.  
  1445. void
  1446. init_const_rtx_hash_table ()
  1447. {
  1448.   bzero (const_rtx_hash_table, sizeof const_rtx_hash_table);
  1449. }
  1450.  
  1451. struct rtx_const
  1452. {
  1453. #ifdef MPW_C31
  1454.   /* Must be certain that these enums are shorts. */
  1455.   enum kind { RTX_DOUBLE, RTX_INT, rtx_const_shortifier = 16000 } kind;
  1456.   enum machine_mode mode;
  1457. #else
  1458.   enum kind { RTX_DOUBLE, RTX_INT } kind : 16;
  1459.   enum machine_mode mode : 16;
  1460. #endif /* MPW_C31 */
  1461.   union {
  1462.     union real_extract du;
  1463.     struct addr_const addr;
  1464.   } un;
  1465. };
  1466.  
  1467. /* Express an rtx for a constant integer (perhaps symbolic)
  1468.    as the sum of a symbol or label plus an explicit integer.
  1469.    They are stored into VALUE.  */
  1470.  
  1471. static void
  1472. decode_rtx_const (mode, x, value)
  1473.      enum machine_mode mode;
  1474.      rtx x;
  1475.      struct rtx_const *value;
  1476. {
  1477.   /* Clear the whole structure, including any gaps.  */
  1478.  
  1479.   {
  1480.     int *p = (int *) value;
  1481.     int *end = (int *) (value + 1);
  1482.     while (p < end)
  1483.       *p++ = 0;
  1484.   }
  1485.  
  1486.   value->kind = RTX_INT;    /* Most usual kind. */
  1487.   value->mode = mode;
  1488.  
  1489.   switch (GET_CODE (x))
  1490.     {
  1491.     case CONST_DOUBLE:
  1492.       value->kind = RTX_DOUBLE;
  1493.       value->mode = GET_MODE (x);
  1494.       bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
  1495.       break;
  1496.  
  1497.     case CONST_INT:
  1498.       value->un.addr.offset = INTVAL (x);
  1499.       break;
  1500.  
  1501.     case SYMBOL_REF:
  1502.       value->un.addr.base = x;
  1503.       break;
  1504.  
  1505.     case LABEL_REF:
  1506.       value->un.addr.base = x;
  1507.       break;
  1508.  
  1509.     case CONST:
  1510.       x = XEXP (x, 0);
  1511.       if (GET_CODE (x) == PLUS)
  1512.     {
  1513.       value->un.addr.base = XEXP (XEXP (x, 0), 0);
  1514.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1515.         abort ();
  1516.       value->un.addr.offset = INTVAL (XEXP (x, 1));
  1517.     }
  1518.       else if (GET_CODE (x) == MINUS)
  1519.     {
  1520.       value->un.addr.base = XEXP (x, 0);
  1521.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1522.         abort ();
  1523.       value->un.addr.offset = - INTVAL (XEXP (x, 1));
  1524.     }
  1525.       else
  1526.     abort ();
  1527.       break;
  1528.  
  1529.     default:
  1530.       abort ();
  1531.     }
  1532.  
  1533.   if (value->kind == RTX_INT && value->un.addr.base != 0)
  1534.     switch (GET_CODE (value->un.addr.base))
  1535.       {
  1536.       case SYMBOL_REF:
  1537.       case LABEL_REF:
  1538.     /* Use the string's address, not the SYMBOL_REF's address,
  1539.        for the sake of addresses of library routines.
  1540.        For a LABEL_REF, compare labels.  */
  1541.     value->un.addr.base = XEXP (value->un.addr.base, 0);
  1542.       }
  1543. }
  1544.  
  1545. /* Compute a hash code for a constant RTL expression.  */
  1546.  
  1547. int
  1548. const_hash_rtx (mode, x)
  1549.      enum machine_mode mode;
  1550.      rtx x;
  1551. {
  1552.   register int hi, i;
  1553.  
  1554.   struct rtx_const value;
  1555.   decode_rtx_const (mode, x, &value);
  1556.  
  1557.   /* Compute hashing function */
  1558.   hi = 0;
  1559.   for (i = 0; i < sizeof value / sizeof (int); i++)
  1560.     hi += ((int *) &value)[i];
  1561.  
  1562.   hi &= (1 << HASHBITS) - 1;
  1563.   hi %= MAX_RTX_HASH_TABLE;
  1564.   return hi;
  1565. }
  1566.  
  1567. /* Compare a constant rtl object X with a constant-descriptor DESC.
  1568.    Return 1 if DESC describes a constant with the same value as X.  */
  1569.  
  1570. static int
  1571. compare_constant_rtx (mode, x, desc)
  1572.      enum machine_mode mode;
  1573.      rtx x;
  1574.      struct constant_descriptor *desc;
  1575. {
  1576.   register int *p = (int *) desc->contents;
  1577.   register int *strp;
  1578.   register int len;
  1579.   struct rtx_const value;
  1580.  
  1581.   decode_rtx_const (mode, x, &value);
  1582.   strp = (int *) &value;
  1583.   len = sizeof value / sizeof (int);
  1584.  
  1585.   /* Compare constant contents.  */
  1586.   while (--len >= 0)
  1587.     if (*p++ != *strp++)
  1588.       return 0;
  1589.  
  1590.   return 1;
  1591. }
  1592.  
  1593. /* Construct a constant descriptor for the rtl-expression X.
  1594.    It is up to the caller to enter the descriptor in the hash table.  */
  1595.  
  1596. static struct constant_descriptor *
  1597. record_constant_rtx (mode, x)
  1598.      enum machine_mode mode;
  1599.      rtx x;
  1600. {
  1601.   struct constant_descriptor *ptr = 0;
  1602.   int buf;
  1603.   struct rtx_const value;
  1604.  
  1605.   decode_rtx_const (mode, x, &value);
  1606.  
  1607.   obstack_grow (saveable_obstack, &ptr, sizeof ptr);
  1608.   obstack_grow (saveable_obstack, &buf, sizeof buf);
  1609.  
  1610.   /* Record constant contents.  */
  1611.   obstack_grow (saveable_obstack, &value, sizeof value);
  1612.  
  1613.   return (struct constant_descriptor *) obstack_finish (saveable_obstack);
  1614. }
  1615.  
  1616. /* Given a constant rtx X, make (or find) a memory constant for its value
  1617.    and return a MEM rtx to refer to it in memory.  */
  1618.  
  1619. rtx
  1620. force_const_mem (mode, x)
  1621.      enum machine_mode mode;
  1622.      rtx x;
  1623. {
  1624.   register int hash;
  1625.   register struct constant_descriptor *desc;
  1626.   char label[256];
  1627.   char *found = 0;
  1628.   rtx def;
  1629.  
  1630.   if (GET_CODE (x) == CONST_DOUBLE
  1631.       && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM)
  1632.     return CONST_DOUBLE_MEM (x);
  1633.  
  1634.   /* Compute hash code of X.  Search the descriptors for that hash code
  1635.      to see if any of them describes X.  If yes, the descriptor records
  1636.      the label number already assigned.  */
  1637.  
  1638.   hash = const_hash_rtx (mode, x);
  1639.  
  1640.   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
  1641.     if (compare_constant_rtx (mode, x, desc))
  1642.       {
  1643.     found = desc->label;
  1644.     break;
  1645.       }
  1646.  
  1647.   if (found == 0)
  1648.     {
  1649.       int align;
  1650.  
  1651.       /* No constant equal to X is known to have been output.
  1652.      Make a constant descriptor to enter X in the hash table.
  1653.      Assign the label number and record it in the descriptor for
  1654.      future calls to this function to find.  */
  1655.  
  1656.       desc = record_constant_rtx (mode, x);
  1657.       desc->next = const_rtx_hash_table[hash];
  1658.       const_rtx_hash_table[hash] = desc;
  1659.  
  1660.       /* Now output assembler code to define that label
  1661.      and follow it with the data of EXP.  */
  1662.  
  1663.       /* First switch to text section.  */
  1664. #ifdef SELECT_RTX_SECTION
  1665.       SELECT_RTX_SECTION (mode, x);
  1666. #else
  1667.       text_section ();
  1668. #endif
  1669.  
  1670.       /* Align the location counter as required by EXP's data type.  */
  1671.       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
  1672.       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  1673.     align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  1674.  
  1675.       if (align > 1)
  1676.     ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (align));
  1677.  
  1678.       /* Output the label itself.  */
  1679.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1680.  
  1681.       /* Output the value of EXP.  */
  1682.       if (GET_CODE (x) == CONST_DOUBLE)
  1683.     {
  1684.       union real_extract u;
  1685.  
  1686.       bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
  1687.       switch (mode)
  1688.         {
  1689.           /* Perhaps change the following to use
  1690.          CONST_DOUBLE_LOW and CONST_DOUBLE_HIGH, rather than u.i.  */
  1691.         case DImode:
  1692. #ifdef ASM_OUTPUT_DOUBLE_INT
  1693.           ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
  1694. #else /* no ASM_OUTPUT_DOUBLE_INT */
  1695. #ifndef WORDS_BIG_ENDIAN
  1696.           /* Output two ints.  */
  1697.           ASM_OUTPUT_INT (asm_out_file,
  1698.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  1699.           ASM_OUTPUT_INT (asm_out_file,
  1700.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  1701. #else
  1702.           /* Output two ints.  */
  1703.           ASM_OUTPUT_INT (asm_out_file,
  1704.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  1705.           ASM_OUTPUT_INT (asm_out_file,
  1706.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  1707. #endif /* WORDS_BIG_ENDIAN */
  1708. #endif /* no ASM_OUTPUT_DOUBLE_INT */
  1709.           break;
  1710.  
  1711. #ifdef APPLE_C
  1712.         /* Do the output for extended floats. */
  1713.         case XFmode:
  1714. #ifdef ASM_OUTPUT_LONG_DOUBLE
  1715.           ASM_OUTPUT_LONG_DOUBLE (asm_out_file, u.d);
  1716. #else
  1717.           fprintf (stderr, "No output for long doubles!\n");
  1718.           abort ();
  1719. #endif
  1720.           break;
  1721. #endif /* APPLE_C */
  1722.         case DFmode:
  1723.           ASM_OUTPUT_DOUBLE (asm_out_file, u.d);
  1724.           break;
  1725.  
  1726.         case SFmode:
  1727.           ASM_OUTPUT_FLOAT (asm_out_file, u.d);
  1728.         }
  1729.     }
  1730.       else
  1731.     switch (mode)
  1732.       {
  1733.       case SImode:
  1734.         ASM_OUTPUT_INT (asm_out_file, x);
  1735.         break;
  1736.  
  1737.       case HImode:
  1738.         ASM_OUTPUT_SHORT (asm_out_file, x);
  1739.         break;
  1740.  
  1741.       case QImode:
  1742.         ASM_OUTPUT_CHAR (asm_out_file, x);
  1743.         break;
  1744.       }
  1745.  
  1746.       /* Create a string containing the label name, in LABEL.  */
  1747.       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1748.  
  1749.       ++const_labelno;
  1750.  
  1751.       desc->label = found
  1752.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  1753.     }
  1754.  
  1755.   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
  1756.  
  1757.   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, desc->label));
  1758.  
  1759.   RTX_UNCHANGING_P (def) = 1;
  1760.   /* Mark the symbol_ref as belonging to this constants pool.  */
  1761.   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
  1762.  
  1763.   if (GET_CODE (x) == CONST_DOUBLE)
  1764.     {
  1765.       if (CONST_DOUBLE_MEM (x) == cc0_rtx)
  1766.     {
  1767.       CONST_DOUBLE_CHAIN (x) = real_constant_chain;
  1768.       real_constant_chain = x;
  1769.     }
  1770.       CONST_DOUBLE_MEM (x) = def;
  1771.     }
  1772.  
  1773.   return def;
  1774. }
  1775.  
  1776. /* Find all the constants whose addresses are referenced inside of EXP,
  1777.    and make sure assembler code with a label has been output for each one.  */
  1778.  
  1779. void
  1780. output_addressed_constants (exp)
  1781.      tree exp;
  1782. {
  1783.   switch (TREE_CODE (exp))
  1784.     {
  1785.     case ADDR_EXPR:
  1786.       {
  1787.     register tree constant = TREE_OPERAND (exp, 0);
  1788.  
  1789.     while (TREE_CODE (constant) == COMPONENT_REF)
  1790.       {
  1791.         constant = TREE_OPERAND (constant, 0);
  1792.       }
  1793.  
  1794.     if (TREE_LITERAL (constant))
  1795.       /* No need to do anything here
  1796.          for addresses of variables or functions.  */
  1797.       output_constant_def (constant);
  1798.       }
  1799.       break;
  1800.  
  1801.     case PLUS_EXPR:
  1802.     case MINUS_EXPR:
  1803.       output_addressed_constants (TREE_OPERAND (exp, 0));
  1804.       output_addressed_constants (TREE_OPERAND (exp, 1));
  1805.       break;
  1806.  
  1807.     case NOP_EXPR:
  1808.     case CONVERT_EXPR:
  1809.       output_addressed_constants (TREE_OPERAND (exp, 0));
  1810.       break;
  1811.  
  1812.     case CONSTRUCTOR:
  1813.       {
  1814.     register tree link;
  1815.     for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1816.       output_addressed_constants (TREE_VALUE (link));
  1817.       }
  1818.       break;
  1819.  
  1820.     case ERROR_MARK:
  1821.       break;
  1822.  
  1823.     default:
  1824.       if (! TREE_LITERAL (exp))
  1825.     abort ();
  1826.     }
  1827. }
  1828.  
  1829. /* Output assembler code for constant EXP to FILE, with no label.
  1830.    This includes the pseudo-op such as ".int" or ".byte", and a newline.
  1831.    Assumes output_addressed_constants has been done on EXP already.
  1832.  
  1833.    Generate exactly SIZE bytes of assembler data, padding at the end
  1834.    with zeros if necessary.  SIZE must always be specified.
  1835.  
  1836.    SIZE is important for structure constructors,
  1837.    since trailing members may have been omitted from the constructor.
  1838.    It is also important for initialization of arrays from string constants
  1839.    since the full length of the string constant might not be wanted.
  1840.    It is also needed for initialization of unions, where the initializer's
  1841.    type is just one member, and that may not be as long as the union.
  1842.  
  1843.    There a case in which we would fail to output exactly SIZE bytes:
  1844.    for a structure constructor that wants to produce more than SIZE bytes.
  1845.    But such constructors will never be generated for any possible input.  */
  1846.  
  1847. void
  1848. output_constant (exp, size)
  1849.      register tree exp;
  1850.      register int size;
  1851. {
  1852.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  1853.   rtx x;
  1854.  
  1855.   if (size == 0)
  1856.     return;
  1857.  
  1858.   /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
  1859.      That way we get the constant (we hope) inside it.  */
  1860.   if (TREE_CODE (exp) == NOP_EXPR
  1861.       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
  1862.     exp = TREE_OPERAND (exp, 0);
  1863.  
  1864.   switch (code)
  1865.     {
  1866.     case INTEGER_TYPE:
  1867.     case ENUMERAL_TYPE:
  1868.     case POINTER_TYPE:
  1869.     case REFERENCE_TYPE:
  1870.       /* ??? What about       (int)((float)(int)&foo + 4)    */
  1871.       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
  1872.     exp = TREE_OPERAND (exp, 0);
  1873.  
  1874. #ifndef ASM_OUTPUT_DOUBLE_INT
  1875.       if (TYPE_MODE (TREE_TYPE (exp)) == DImode)
  1876.     {
  1877.       if (TREE_CODE (exp) == INTEGER_CST)
  1878.         {
  1879. #ifndef WORDS_BIG_ENDIAN
  1880.           ASM_OUTPUT_INT (asm_out_file,
  1881.                   gen_rtx (CONST_INT, VOIDmode,
  1882.                        TREE_INT_CST_LOW (exp)));
  1883.           ASM_OUTPUT_INT (asm_out_file,
  1884.                   gen_rtx (CONST_INT, VOIDmode,
  1885.                        TREE_INT_CST_HIGH (exp)));
  1886. #else
  1887.           ASM_OUTPUT_INT (asm_out_file,
  1888.                   gen_rtx (CONST_INT, VOIDmode,
  1889.                        TREE_INT_CST_HIGH (exp)));
  1890.           ASM_OUTPUT_INT (asm_out_file,
  1891.                   gen_rtx (CONST_INT, VOIDmode,
  1892.                        TREE_INT_CST_LOW (exp)));
  1893. #endif
  1894.           size -= 8;
  1895.           break;
  1896.         }
  1897.       else
  1898.         error ("8-byte integer constant expression too complicated");
  1899.  
  1900.       break;
  1901.     }
  1902. #endif /* no ASM_OUTPUT_DOUBLE_INT */
  1903.  
  1904.       x = expand_expr (exp, 0, VOIDmode, EXPAND_SUM);
  1905.  
  1906.       if (size == 1)
  1907.     {
  1908.       ASM_OUTPUT_CHAR (asm_out_file, x);
  1909.       size -= 1;
  1910.     }
  1911.       else if (size == 2)
  1912.     {
  1913.       ASM_OUTPUT_SHORT (asm_out_file, x);
  1914.       size -= 2;
  1915.     }
  1916.       else if (size == 4)
  1917.     {
  1918.       ASM_OUTPUT_INT (asm_out_file, x);
  1919.       size -= 4;
  1920.     }
  1921. #ifdef ASM_OUTPUT_DOUBLE_INT
  1922.       else if (size == 8)
  1923.     {
  1924.       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
  1925.       size -= 8;
  1926.     }
  1927. #endif /* ASM_OUTPUT_DOUBLE_INT */
  1928.       else
  1929.     abort ();
  1930.  
  1931.       break;
  1932.  
  1933.     case REAL_TYPE:
  1934.       if (TREE_CODE (exp) != REAL_CST)
  1935.     error ("initializer for floating value is not a floating constant");
  1936.       else
  1937.     {
  1938.       REAL_VALUE_TYPE d;
  1939.       jmp_buf output_constant_handler;
  1940.  
  1941.       d = TREE_REAL_CST (exp);
  1942.       if (setjmp (output_constant_handler))
  1943.         {
  1944.           error ("floating point trap outputting a constant");
  1945. #ifdef REAL_IS_NOT_DOUBLE
  1946.           bzero (&d, sizeof d);
  1947.           d = REAL_VALUE_ATOF ("0");
  1948. #else
  1949.           d = 0;
  1950. #endif
  1951.         }
  1952.       set_float_handler (output_constant_handler);
  1953.  
  1954.       if (size < 4)
  1955.         break;
  1956.       else if (size < 8)
  1957.         {
  1958.           ASM_OUTPUT_FLOAT (asm_out_file, d);
  1959.           size -= 4;
  1960.         }
  1961.       else
  1962.         {
  1963. #ifdef APPLE_C
  1964.           /* Decide about how to dump out double and long double constants.
  1965.          Note that the exact amount dumped depends on the size of long
  1966.          doubles. */
  1967.           if (size < 10)
  1968.         {
  1969.           ASM_OUTPUT_DOUBLE (asm_out_file, d);
  1970.           size -= 8;
  1971.         }
  1972.           else
  1973.         {
  1974.           ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
  1975.           size -= GET_MODE_SIZE (XFmode);
  1976.         }
  1977. #else
  1978.           ASM_OUTPUT_DOUBLE (asm_out_file, d);
  1979.           size -= 8;
  1980. #endif /* APPLE_C */
  1981.         }
  1982.       set_float_handler (0);
  1983.      }
  1984.       break;
  1985.  
  1986.     case COMPLEX_TYPE:
  1987.       output_constant (TREE_REALPART (exp), size / 2);
  1988.       output_constant (TREE_IMAGPART (exp), size / 2);
  1989.       size -= (size / 2) * 2;
  1990.       break;
  1991.  
  1992.     case ARRAY_TYPE:
  1993.       if (TREE_CODE (exp) == CONSTRUCTOR)
  1994.     {
  1995.       output_constructor (exp, size);
  1996.       return;
  1997.     }
  1998.       else if (TREE_CODE (exp) == STRING_CST)
  1999.     {
  2000.       int excess = 0;
  2001.  
  2002.       if (size > TREE_STRING_LENGTH (exp))
  2003.         {
  2004.           excess = size - TREE_STRING_LENGTH (exp);
  2005.           size = TREE_STRING_LENGTH (exp);
  2006.         }
  2007.  
  2008.       assemble_string (TREE_STRING_POINTER (exp), size);
  2009.       size = excess;
  2010.     }
  2011.       else
  2012.     abort ();
  2013.       break;
  2014.  
  2015.     case RECORD_TYPE:
  2016.     case UNION_TYPE:
  2017.       if (TREE_CODE (exp) == CONSTRUCTOR)
  2018.     output_constructor (exp, size);
  2019.       else
  2020.     abort ();
  2021.       return;
  2022.     }
  2023.  
  2024.   if (size > 0)
  2025.     ASM_OUTPUT_SKIP (asm_out_file, size);
  2026. }
  2027.  
  2028. /* Subroutine of output_constant, used for CONSTRUCTORs
  2029.    (aggregate constants).
  2030.    Generate at least SIZE bytes, padding if necessary.  */
  2031.  
  2032. void
  2033. output_constructor (exp, size)
  2034.      tree exp;
  2035.      int size;
  2036. {
  2037.   register tree link, field = 0;
  2038.   /* Number of bytes output or skipped so far.
  2039.      In other words, current position within the constructor.  */
  2040.   int total_bytes = 0;
  2041.   /* Non-zero means BYTE contains part of a byte, to be output.  */
  2042.   int byte_buffer_in_use = 0;
  2043.   register int byte;
  2044.  
  2045.   if (HOST_BITS_PER_INT < BITS_PER_UNIT)
  2046.     abort ();
  2047.  
  2048.   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
  2049.       || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
  2050.     field = TYPE_FIELDS (TREE_TYPE (exp));
  2051.  
  2052.   /* As LINK goes through the elements of the constant,
  2053.      FIELD goes through the structure fields, if the constant is a structure.
  2054.      But the constant could also be an array.  Then FIELD is zero.  */
  2055.   for (link = CONSTRUCTOR_ELTS (exp);
  2056.        link;
  2057.        link = TREE_CHAIN (link),
  2058.        field = field ? TREE_CHAIN (field) : 0)
  2059.     {
  2060.       tree val = TREE_VALUE (link);
  2061.  
  2062.       /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.  */
  2063.       if (TREE_CODE (val) == NOP_EXPR
  2064.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
  2065.     val = TREE_OPERAND (val, 0);
  2066.  
  2067.       if (field == 0
  2068.       || (DECL_MODE (field) != BImode))
  2069.     {
  2070.       register int fieldsize;
  2071.  
  2072.       /* An element that is not a bit-field.
  2073.          Output any buffered-up bit-fields preceding it.  */
  2074.       if (byte_buffer_in_use)
  2075.         {
  2076.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2077.           total_bytes++;
  2078.           byte_buffer_in_use = 0;
  2079.         }
  2080.  
  2081.       /* Advance to offset of this element.
  2082.          Note no alignment needed in an array, since that is guaranteed
  2083.          if each element has the proper size.  */
  2084.       if (field != 0 && DECL_OFFSET (field) / BITS_PER_UNIT != total_bytes)
  2085.         {
  2086.           ASM_OUTPUT_SKIP (asm_out_file,
  2087.                    (DECL_OFFSET (field) / BITS_PER_UNIT
  2088.                 - total_bytes));
  2089.           total_bytes = DECL_OFFSET (field) / BITS_PER_UNIT;
  2090.         }
  2091.  
  2092.       /* Determine size this element should occupy.  */
  2093.       if (field)
  2094.         {
  2095.           if (! TREE_LITERAL (DECL_SIZE (field)))
  2096.         abort ();
  2097.           fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field))
  2098.         * DECL_SIZE_UNIT (field);
  2099.           fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  2100.         }
  2101.       else
  2102.         fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
  2103.  
  2104.       /* Output the element's initial value.  */
  2105.       output_constant (val, fieldsize);
  2106.  
  2107.       /* Count its size.  */
  2108.       total_bytes += fieldsize;
  2109.     }
  2110.       else if (TREE_CODE (val) != INTEGER_CST)
  2111.     error ("invalid initial value for member `%s'",
  2112.            IDENTIFIER_POINTER (DECL_NAME (field)));
  2113.       else
  2114.     {
  2115.       /* Element that is a bit-field.  */
  2116.  
  2117.       int next_offset = DECL_OFFSET (field);
  2118.       int end_offset
  2119.         = (next_offset
  2120.            + (TREE_INT_CST_LOW (DECL_SIZE (field))
  2121.           * DECL_SIZE_UNIT (field)));
  2122.  
  2123.       /* If this field does not start in this (or, next) byte,
  2124.          skip some bytes.  */
  2125.       if (next_offset / BITS_PER_UNIT != total_bytes)
  2126.         {
  2127.           /* Output remnant of any bit field in previous bytes.  */
  2128.           if (byte_buffer_in_use)
  2129.         {
  2130.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2131.           total_bytes++;
  2132.           byte_buffer_in_use = 0;
  2133.         }
  2134.  
  2135.           /* If still not at proper byte, advance to there.  */
  2136.           if (next_offset / BITS_PER_UNIT != total_bytes)
  2137.         {
  2138.           ASM_OUTPUT_SKIP (asm_out_file,
  2139.                    next_offset / BITS_PER_UNIT - total_bytes);
  2140.           total_bytes = next_offset / BITS_PER_UNIT;
  2141.         }
  2142.         }
  2143.  
  2144.       if (! byte_buffer_in_use)
  2145.         byte = 0;
  2146.  
  2147.       /* We must split the element into pieces that fall within
  2148.          separate bytes, and combine each byte with previous or
  2149.          following bit-fields.  */
  2150.  
  2151.       /* next_offset is the offset n fbits from the begining of
  2152.          the structure to the next bit of this element to be processed.
  2153.          end_offset is the offset of the first bit past the end of
  2154.          this element.  */
  2155.       while (next_offset < end_offset)
  2156.         {
  2157.           int this_time;
  2158.           int next_byte = next_offset / BITS_PER_UNIT;
  2159.           int next_bit = next_offset % BITS_PER_UNIT;
  2160.  
  2161.           /* Advance from byte to byte
  2162.          within this element when necessary.  */
  2163.           while (next_byte != total_bytes)
  2164.         {
  2165.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2166.           total_bytes++;
  2167.           byte = 0;
  2168.         }
  2169.  
  2170.           /* Number of bits we can process at once
  2171.          (all part of the same byte).  */
  2172.           this_time = MIN (end_offset - next_offset,
  2173.                    BITS_PER_UNIT - next_bit);
  2174. #ifdef BYTES_BIG_ENDIAN
  2175.           /* On big-endian machine, take the most significant bits
  2176.          first (of the bits that are significant)
  2177.          and put them into bytes from the most significant end.  */
  2178.           byte |= (((TREE_INT_CST_LOW (val)
  2179.              >> (end_offset - next_offset - this_time))
  2180.             & ((1 << this_time) - 1))
  2181.                << (BITS_PER_UNIT - this_time - next_bit));
  2182. #else
  2183.           /* On little-endian machines,
  2184.          take first the least significant bits of the value
  2185.          and pack them starting at the least significant
  2186.          bits of the bytes.  */
  2187.           byte |= ((TREE_INT_CST_LOW (val)
  2188.             >> (next_offset - DECL_OFFSET (field)))
  2189.                & ((1 << this_time) - 1)) << next_bit;
  2190. #endif
  2191.           next_offset += this_time;
  2192.           byte_buffer_in_use = 1;
  2193.         }
  2194.     }
  2195.     }
  2196.   if (byte_buffer_in_use)
  2197.     {
  2198.       ASM_OUTPUT_BYTE (asm_out_file, byte);
  2199.       total_bytes++;
  2200.     }
  2201.   if (total_bytes < size)
  2202.     ASM_OUTPUT_SKIP (asm_out_file, size - total_bytes);
  2203. }
  2204.  
  2205. #ifdef APPLE_HAX
  2206. /* This is all part of the scheme to produce the appropriate import
  2207.    and export declarations. */
  2208.  
  2209. struct impsym {
  2210.   char *name;
  2211.   char *modulename;
  2212.   struct impsym *next;
  2213. };
  2214.  
  2215. static struct impsym *implist;
  2216.  
  2217. char *mnames[10];
  2218.  
  2219. int mtop;
  2220.  
  2221. /* This particular string copy is pure paranoia. */
  2222.  
  2223. char *
  2224. copy_string(str)
  2225. char *str;
  2226. {
  2227.   char *rslt;
  2228.  
  2229.   rslt = (char *) xmalloc(strlen(str)+4);
  2230.   strcpy(rslt, str);
  2231.   return rslt;
  2232. }
  2233.  
  2234. /* Do the allocations for this file. */
  2235.  
  2236. init_import_for_file()
  2237. {
  2238.   implist = NULL;
  2239.   mtop = 0;
  2240.   mnames[mtop] = "*";
  2241. }
  2242.  
  2243. start_module (name)
  2244. char *name;
  2245. {
  2246.   if (mtop >= 9)
  2247.     abort ();
  2248.   mnames[++mtop] = copy_string (name);
  2249. #ifdef TARGET_BSTR
  2250.   if (TARGET_BSTR)
  2251.     clear_const_hash_table ();
  2252. #endif
  2253. }
  2254.  
  2255. finish_module (name)
  2256. char *name;
  2257. {
  2258.   if (strcmp(mnames[mtop], name) == 0)
  2259.     --mtop;
  2260.   if (mtop < 0)
  2261.     abort ();
  2262. }
  2263.  
  2264. char *
  2265. add_section_mark (str)
  2266. char *str;
  2267. {
  2268.   char *label;
  2269. #if 0
  2270.   /* Ideal */
  2271.   label = (char *) alloca (strlen (str) + 2);
  2272.   sprintf (label, "0%s", str);
  2273.   obstack_copy0 (saveable_obstack, label, strlen (label));
  2274. #else
  2275.   label = (char *) xmalloc (strlen (str) + 10);
  2276.   sprintf (label, "0%s", str);
  2277. #endif
  2278.   return label;
  2279. }
  2280.  
  2281. match_name (name, impentry)
  2282. char *name;
  2283. struct impsym *impentry;
  2284. {
  2285.   return ((strcmp (name, impentry->name) == 0
  2286.        || strcmp (name+1, (impentry->name)+1) == 0)
  2287.       && (*(impentry->modulename) == '*'
  2288.           || strcmp (mnames[mtop], impentry->modulename) == 0));
  2289. }
  2290.  
  2291. /* This function will decide about importation of variables according to
  2292.    whether they are code or data. */
  2293.  
  2294. import_a_declared_name (decl)
  2295.      tree decl;
  2296. {
  2297. #ifdef IMPORT_NAMES
  2298.   rtx rtl = DECL_RTL (decl);
  2299.  
  2300.   if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  2301.     {
  2302.       if (TREE_CODE (decl) == FUNCTION_DECL)
  2303.         import_a_function(XSTR (XEXP (rtl, 0), 0));
  2304.       else if (TREE_CODE (decl) == VAR_DECL)
  2305.         import_a_variable(XSTR (XEXP (rtl, 0), 0));
  2306.       else abort();
  2307.     }
  2308. #endif
  2309. }
  2310.  
  2311. /* Import a data name.  This just records, actual output doesn't occur
  2312.    until all the names in a module have been seen.  If the name is defined
  2313.    in this module, no import will be issued.  If it has already been seen
  2314.    at all, don't even bother to record it. */
  2315.  
  2316. import_a_variable(name)
  2317. char *name;
  2318. {
  2319. #ifdef IMPORT_NAMES
  2320.   struct impsym *tmp;
  2321.  
  2322.   /* Don't import direct function definitions */
  2323.   if (name[1] == ';') return;
  2324.   for (tmp = implist; tmp != NULL; tmp = tmp->next)
  2325.     if (match_name (name, tmp))
  2326.       return;
  2327.   tmp = (struct impsym *) xmalloc (sizeof (struct impsym));
  2328.   tmp->name = copy_string(name);
  2329.   tmp->modulename = mnames[mtop];
  2330.   tmp->next = implist;
  2331.   implist = tmp;
  2332. #endif
  2333. }
  2334.  
  2335. /* Import a code name, but ignore if it's already occurred. */
  2336.  
  2337. import_a_function(name)
  2338. char *name;
  2339. {
  2340. #ifdef IMPORT_NAMES
  2341.   struct impsym *tmp;
  2342.  
  2343.   /* Don't import direct function definitions */
  2344.   if (name[1] == ';') return;
  2345.   for (tmp = implist; tmp != NULL; tmp = tmp->next)
  2346.     if (match_name (name, tmp))
  2347.       return;
  2348.   tmp = (struct impsym *) xmalloc (sizeof (struct impsym));
  2349.   tmp->name = copy_string(name);
  2350.   tmp->modulename = mnames[mtop];
  2351.   tmp->next = implist;
  2352.   implist = tmp;
  2353. #endif
  2354. }
  2355.  
  2356. /* Define or export a data name, or more accurately erase its importation. */
  2357.  
  2358. define_a_variable (name)
  2359. char *name;
  2360. {
  2361. #ifdef IMPORT_NAMES
  2362.   struct impsym *tmp;
  2363.  
  2364.   for (tmp = implist; tmp; tmp = tmp->next)
  2365.     if (match_name (name, tmp))
  2366.       {
  2367.     tmp->name = "";
  2368.     return;
  2369.       }
  2370. #endif
  2371. }
  2372.  
  2373. define_a_function (name)
  2374. char *name;
  2375. {
  2376. #ifdef IMPORT_NAMES
  2377.   struct impsym *tmp;
  2378.  
  2379.   for (tmp = implist; tmp; tmp = tmp->next)
  2380.     if (match_name (name, tmp))
  2381.       {
  2382.     tmp->name = "";
  2383.     return;
  2384.       }
  2385. #endif
  2386. }
  2387.  
  2388. /* Import every symbol in the named module into the current module. */
  2389.  
  2390. add_inline_imports (inlined)
  2391. char *inlined;
  2392. {
  2393. #ifdef IMPORT_NAMES
  2394.   struct impsym *tmp;
  2395.  
  2396.   for (tmp = implist; tmp; tmp = tmp->next)
  2397.     if (strcmp(inlined, tmp->modulename) == 0)
  2398.       {
  2399.     import_a_function (tmp->name);
  2400.       }
  2401. #endif
  2402. }
  2403.  
  2404. /* Any symbol undefined by a function must be imported (this makes for lots
  2405.    of imports sometimes).  Must be careful about code vs data symbols.
  2406.    To save some asm instructions, all the data symbols are dumped first.
  2407.    (Note that the loops are written such that the output is correct even
  2408.    if the repn changes.)  */
  2409.  
  2410. import_undefined(file)
  2411. FILE *file;
  2412. {
  2413. #ifdef IMPORT_NAMES
  2414.   struct impsym *tmp;
  2415.  
  2416.   for (tmp = implist; tmp; tmp = tmp->next)
  2417.     {
  2418.       if (strlen (tmp->name) > 0
  2419.       && (strcmp(mnames[mtop], tmp->modulename) == 0
  2420.           || (*(tmp->modulename) == '*' && (tmp->name)[1] == 'L'))
  2421.       && *(tmp->name) == '2')
  2422.     {
  2423. #ifdef ASM_IMPORT_NAME
  2424.       ASM_IMPORT_NAME (file, tmp->name);
  2425. #endif
  2426.     }
  2427.     }
  2428.   for (tmp = implist; tmp; tmp = tmp->next)
  2429.     {
  2430.       if (strlen (tmp->name) > 0
  2431.       && (strcmp(mnames[mtop], tmp->modulename) == 0
  2432.           || (*(tmp->modulename) == '*' && (tmp->name)[1] == 'L'))
  2433.       && *(tmp->name) != '2')
  2434.     {
  2435. #ifdef ASM_IMPORT_NAME
  2436.       ASM_IMPORT_NAME (file, tmp->name);
  2437. #endif
  2438.     }
  2439.     }
  2440. #endif
  2441. }
  2442. #endif /* APPLE_HAX */
  2443.  
  2444. #ifdef APPLE_C
  2445. /* This transforms a string into all-upper-case, just the way MPW Pascal
  2446.    likes it. */
  2447.  
  2448. #include <ctype.h>
  2449.  
  2450. string_upcase(str)
  2451. char *str;
  2452. {
  2453.   int i;
  2454.  
  2455.   for (i = 0; str[i] != '\0'; ++i)
  2456.     {
  2457.       if (islower(str[i])) str[i] = toupper(str[i]);
  2458.     }
  2459. }
  2460.  
  2461. /* This is a rather strange way to build a direct definition, but seems to
  2462.    work - make a comma-separated list of numbers, followed by semicolon,
  2463.    followed by the original name.  This form is correct for MPW Asm, but
  2464.    might have to be modified by an aux-output.c routine to be used with
  2465.    any other assembler. */
  2466.  
  2467. /* (Should check that defn is a list of 16-bit numbers.) */
  2468.  
  2469. char *
  2470. build_direct_defn(name, init)
  2471.      char *name;
  2472.      tree init;
  2473. {
  2474.     tree tail;
  2475.     char *tmpbuf;
  2476.     char tmp2[20];
  2477.     int tmpsize = 20 + strlen (name);
  2478.  
  2479.     /* Calculate how much buffer we'll need (could be done with obstack?) */
  2480.     if (TREE_CODE (init) == INTEGER_CST)
  2481.       tmpsize += 20;
  2482.     else
  2483.       {
  2484.     tail = CONSTRUCTOR_ELTS (init);
  2485.     while (tail != 0)
  2486.       {
  2487.         tmpsize += 20;
  2488.         tail = TREE_CHAIN (tail);
  2489.       }
  2490.       }
  2491.     tmpbuf = (char *) xmalloc (tmpsize);
  2492.     /* Leave extra hole for code/data id, plus semicolon as direct fn flag,
  2493.         plus a blank to fool assemble_name. */
  2494.     sprintf (tmpbuf, "0; ");
  2495.     if (TREE_CODE (init) == INTEGER_CST)
  2496.       {
  2497.     sprintf(tmp2, "%d", TREE_INT_CST_LOW (init));
  2498.     strcat (tmpbuf, tmp2);
  2499.       }
  2500.     else
  2501.       {
  2502.     tail = CONSTRUCTOR_ELTS (init);
  2503.     /* Go through list getting numbers. */
  2504.     while (tail != 0)
  2505.       {
  2506.         sprintf(tmp2, "%d", TREE_INT_CST_LOW (TREE_VALUE (tail)));
  2507.         strcat (tmpbuf, tmp2);
  2508.         tail = TREE_CHAIN (tail);
  2509.         if (tail != 0)
  2510.           strcat (tmpbuf, ", ");
  2511.       }
  2512.       }
  2513.     /* Optional but useful - append the original name. */
  2514.     strcat (tmpbuf, "  ;  ");
  2515.     strcat (tmpbuf, name+1);  /* add one because of name mod */
  2516.     return tmpbuf;
  2517. }
  2518. #endif /* APPLE_C */
  2519.